package com.zz.common.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

public abstract class DeviceUtil {
	
    public static int px2dip(Context context, float pxValue){ 
    	final float scale = context.getResources().getDisplayMetrics().density; 
    	return (int)(pxValue / scale + 0.5f); 
    } 
    
    public static int dip2px(Context context, float dipValue){ 
    	final float scale = context.getResources().getDisplayMetrics().density; 
    	return (int)(dipValue * scale + 0.5f); 
	}
    
	public static String getMacAddr(Context context){
		String result = "";
		WifiManager wfm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
		WifiInfo info = wfm.getConnectionInfo();
		if(null != info) {
			result = info.getMacAddress();
		}
		return result;
	}
	
	public static String getIMEI(Context ctx) {
		TelephonyManager tm = (TelephonyManager) ctx
				.getSystemService(Context.TELEPHONY_SERVICE);
		String imei = tm.getDeviceId();

		if (null == imei || "".equals(imei)) {
			imei = "000000000000000";
		}

		return imei;
	}
	
	public static String getMac(Context ctx){
		WifiManager wifiMgr = (WifiManager) ctx
		.getSystemService(Context.WIFI_SERVICE);
		String mac = wifiMgr.getConnectionInfo().getMacAddress();
		return mac;
	}
	
	public static String getPeerId(Context c) {
		String peerid = getIMEI(c)+"V";
		if ("000000000000000V".equals(peerid)){
			String mac = getMac(c);
			if (mac!=null){
				peerid = mac.replace(":", "")+"003V";
			}
		}
		return peerid;
	}
	
	public static int getScreenWidth(Context context) {
		return context.getResources().getDisplayMetrics().widthPixels;
	}
	
	public static int getScreenHeight(Context context) {
		return context.getResources().getDisplayMetrics().heightPixels;
	}
}
